local skel = fk.CreateSkill {
  name = "emo__daowu",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__daowu"] = "刀舞",
  [":emo__daowu"] = "锁定技，结束阶段，本回合每有六张牌进入弃牌堆，你获得一张刺【杀】；你使用普通【杀】次数上限-1，使用特殊【杀】无次数限制。",
}

skel:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(skel.name) and player.phase == Player.Finish then
      local num = 0
      player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
        for _, move in ipairs(e.data) do
          if move.toArea == Card.DiscardPile then
            num = num + #move.moveInfo
          end
        end
        return false
      end, Player.HistoryTurn)
      num = num // 6
      if num > 0 then
        event:setCostData(self, num)
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local num = event:getCostData(self)
    local cards = room:getCardsFromPileByRule("stab__slash", num, "allPiles")
    for i = 1, num - #cards do
      table.insert(cards, room:printCard("stab__slash", Card.Spade, math.random(6, 9)).id)
    end
    room:obtainCard(player, cards, false, fk.ReasonPrey, player, skel.name)
  end,
})

skel:addEffect("targetmod", {
  residue_func = function(self, player, skill, scope, card)
    if player:hasSkill(skel.name) and card and card.name == "slash" and scope == Player.HistoryPhase then
      return -1
    end
  end,
  bypass_times = function(self, player, skill, scope, card)
    return player:hasSkill(skel.name) and card and card.name ~= "slash" and card.trueName == "slash"
  end,
})

return skel
